var http = require('http');
var request = require('request');
http.createServer(function (request, response) {
    // 发送 HTTP 头部 
    // HTTP 状态值: 200 : OK
    // 内容类型: text/plain
    response.writeHead(200, {'Content-Type': 'text/plain'});

    // 发送响应数据 "Hello World"
    response.end('Hello World...\n');    
}).listen(8081);
console.log('Server running at http://127.0.0.1:8081/');
//PUT /api/Form/b713476c-738b-4058-865f-d85ac73f49ac?diseaseId=15 HTTP/1.1
var h = {
    Host: 'www.cnrds.net',
    Connection: 'keep-alive',
    "Content-Length": 4798,
    Accept: '*/*',
    Origin: 'http://www.cnrds.net',
    "X-Requested-With": 'XMLHttpRequest',
    "User-Agent": 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36',
    "Content-Type": 'application/json',
    Referer: 'http://www.cnrds.net/Pages/EditForm/15/b713476c-738b-4058-865f-d85ac73f49ac',
    "Accept-Encoding": 'gzip, deflate',
    "Accept-Language": 'zh-CN,zh;q=0.9',
    Cookie: 'ASP.NET_SessionId=211cijocmaoghjinqaabrr1w; .AspNet.ApplicationCookie=3Qm3bqqjU_GwIMuNoIOmvBnmfl_F2J9oFTfoAzmy3Yh_7juQhqPysY6DlrzuF5QGwbcKwAyFzWbOZmGGONmZi_PHmGyeZObpRGEX7DU_7IqDq9BOCA4egNR6fxM2XseBdz73UoBy3ImWotsbnvHKMYvuHYR3ZbpphfzIGJlaCNrj0KAQICV2jaNDC5tu1fwxkpQMmqEHjyw7VfyIWBB6UK2p4Y3vr6yK1rGW5imU1qKYZMxjRF4RsJrvapzZw_4y9ZSGu5EgIp2FtGQjM3cqVftAwWHujzL0ibBsHzWtaIJ6GazwK4mMmqEUlhDvkwm6t6K4tXIQi7a7sfig-TygcQfEUfwXPvWNGIY4RWclkOnK9cv2YGkEYaSkkELzk3fnRXHU_EhgbD2Ym4R5bTsGyEPa_TvNGK12hPJLA9RIbxNMXeCG4-x5Fkp-F1vdZGoADAqdFQ8ctUMPHmCh5i3YRsekz8vtUEzVFtGtYdz1iSY'
};
var cookie = 'ASP.NET_SessionId=211cijocmaoghjinqaabrr1w; .AspNet.ApplicationCookie=3Qm3bqqjU_GwIMuNoIOmvBnmfl_F2J9oFTfoAzmy3Yh_7juQhqPysY6DlrzuF5QGwbcKwAyFzWbOZmGGONmZi_PHmGyeZObpRGEX7DU_7IqDq9BOCA4egNR6fxM2XseBdz73UoBy3ImWotsbnvHKMYvuHYR3ZbpphfzIGJlaCNrj0KAQICV2jaNDC5tu1fwxkpQMmqEHjyw7VfyIWBB6UK2p4Y3vr6yK1rGW5imU1qKYZMxjRF4RsJrvapzZw_4y9ZSGu5EgIp2FtGQjM3cqVftAwWHujzL0ibBsHzWtaIJ6GazwK4mMmqEUlhDvkwm6t6K4tXIQi7a7sfig-TygcQfEUfwXPvWNGIY4RWclkOnK9cv2YGkEYaSkkELzk3fnRXHU_EhgbD2Ym4R5bTsGyEPa_TvNGK12hPJLA9RIbxNMXeCG4-x5Fkp-F1vdZGoADAqdFQ8ctUMPHmCh5i3YRsekz8vtUEzVFtGtYdz1iSY';
var HOST = 'www.cnrds.net';
var PORT = '';
var method = 'PUT';
var bodydata = {"resultId":"b713476c-738b-4058-865f-d85ac73f49ac","diseaseId":15,"formInstKey":"ShiYanShiJianCha","mainId":"a9f9d849-aeca-44de-90a5-b46a955305b3","parentId":"a9f9d849-aeca-44de-90a5-b46a955305b3","fullJson":"{\"year\":2019,\"jiDu\":\"第二季度\",\"xueChangGui_date\":\"2019-05-02\",\"xueChangGui_baiXiBao_val\":4.52,\"xueChangGui_baiXiBao_isJianCha\":\"\",\"xueChangGui_xueHongDanBanbai_val\":114,\"xueChangGui_xueHongDanBanbai_isJianCha\":\"\",\"xueChangGui_hongXiBaoJiShu_val\":\"\",\"xueChangGui_hongXiBaoJiShu_isJianCha\":\"未查\",\"xueChangGui_hongXiBaoJiYa_val\":34.7,\"xueChangGui_hongXiBaoJiYa_isJianCha\":\"\",\"xueChangGui_wangZhiHongXiBao_val\":\"\",\"xueChangGui_wangZhiHongXiBao_isJianCha\":\"未查\",\"xueChangGui_xueXiaoBan_val\":118,\"xueChangGui_xueXiaoBan_isJianCha\":\"\",\"guKuangWuZhiDaiXie_date\":\"2019-05-02\",\"guKuangWuZhiDaiXie_xueZongGai_val\":1.95,\"guKuangWuZhiDaiXie_xueZongGai_isJianCha\":\"\",\"guKuangWuZhiDaiXie_youLiGai_val\":\"\",\"guKuangWuZhiDaiXie_youLiGai_isJianCha\":\"未查\",\"guKuangWuZhiDaiXie_xueLin_val\":1.49,\"guKuangWuZhiDaiXie_xueLin_isJianCha\":\"\",\"guKuangWuZhiDaiXie_gaiLinChengJi_val\":2.91,\"guKuangWuZhiDaiXie_gaiLinChengJi_danWei\":\"\",\"guKuangWuZhiDaiXie_quanDuanJiaPangXianJiSu_val\":\"\",\"guKuangWuZhiDaiXie_quanDuanJiaPangXianJiSu_isJianCha\":\"未查\",\"guKuangWuZhiDaiXie_AKP_val\":\"\",\"guKuangWuZhiDaiXie_AKP_isJianCha\":\"\",\"tieDaiXie_date\":\"2019-05-02\",\"tieDaiXie_xueQingTie_val\":\"\",\"tieDaiXie_xueQingTie_isJianCha\":\"未查\",\"tieDaiXie_zongTieJieHeLi_val\":\"\",\"tieDaiXie_zongTieJieHeLi_isJianCha\":\"未查\",\"tieDaiXie_zhuanTieBaoHeDu_val\":\"\",\"tieDaiXie_tieDanBai_val\":\"\",\"tieDaiXie_tieDanBai_isJianCha\":\"\",\"shengHuaJianCha_date\":\"2019-05-02\",\"shengHuaJianCha_niaoSu_val\":\"\",\"shengHuaJianCha_niaoSu_danWei\":\"mmol/L\",\"shengHuaJianCha_niaoSu1_isJianCha\":\"\",\"shengHuaJianCha_JiGan_val\":\"\",\"shengHuaJianCha_JiGan_danWei\":\"μmol/L\",\"shengHuaJianCha_JiGan1_isJianCha\":\"\",\"shengHuaJianCha_xueNiaoSuan_val\":\"\",\"shengHuaJianCha_xueNiaoSuan_isJianCha\":\"\",\"shengHuaJianCha_xueZongDanBai_val\":\"\",\"shengHuaJianCha_xueZongDanBai_isJianCha\":\"\",\"shengHuaJianCha_xueBaiDanBai_val\":\"\",\"shengHuaJianCha_xueBaiDanBai_isJianCha\":\"未查\",\"shengHuaJianCha_AST_val\":\"\",\"shengHuaJianCha_AST_isJianCha\":\"\",\"shengHuaJianCha_ALT_val\":\"\",\"shengHuaJianCha_ALT_isJianCha\":\"\",\"shengHuaJianCha_zongDanHongSu_val\":\"\",\"shengHuaJianCha_zongDanHongSu_isJianCha\":\"\",\"shengHuaJianCha_ganYouSanZhi_val\":\"\",\"shengHuaJianCha_ganYouSanZhi_isJianCha\":\"\",\"shengHuaJianCha_zongDanGuChun_val\":\"\",\"shengHuaJianCha_zongDanGuChun_isJianCha\":\"\",\"shengHuaJianCha_diMiDuZhiDanBai_val\":\"\",\"shengHuaJianCha_diMiDuZhiDanBai_isJianCha\":\"\",\"shengHuaJianCha_gaoMiDuZhiDanBai_val\":\"\",\"shengHuaJianCha_gaoMiDuZhiDanBai_isJianCha\":\"\",\"shengHuaJianCha_xueTang_val\":\"\",\"shengHuaJianCha_xueTang_isJianCha\":\"\",\"shengHuaJianCha_xueJia_val\":4.9,\"shengHuaJianCha_xueJia_isJianCha\":\"\",\"shengHuaJianCha_xueNa_val\":\"\",\"shengHuaJianCha_xueNa_isJianCha\":\"\",\"shengHuaJianCha_xueLv_val\":\"\",\"shengHuaJianCha_xueLv_isJianCha\":\"\",\"shengHuaJianCha_xueMei_val\":\"\",\"shengHuaJianCha_xueMei_isJianCha\":\"\",\"shengHuaJianCha_xueChen_val\":\"\",\"shengHuaJianCha_xueChen_isJianCha\":\"\",\"shengHuaJianCha_erYangHuaTan_val\":\"\",\"shengHuaJianCha_erYangHuaTan_isJianCha\":\"\",\"yingYangYuYanZheng_date\":\"2019-05-02\",\"yingYangYuYanZheng_CFanYingDanBai_val\":\"\",\"yingYangYuYanZheng_CFanYingDanBai_isJianCha\":\"未查\",\"yingYangYuYanZheng_qianBaiDanBai_val\":\"\",\"yingYangYuYanZheng_qianBaiDanBai_isJianCha\":\"未查\",\"yingYangYuYanZheng_weiQiuDanBai_val\":\"\",\"yingYangYuYanZheng_weiQiuDanBai_isJianCha\":\"未查\",\"chuanRanBing_date\":\"2019-05-02\",\"chuanRanBing_HBsAg_val\":\"\",\"chuanRanBing_HBsAg_isJianCha\":\"未查\",\"chuanRanBing_AntiHBs_val\":\"\",\"chuanRanBing_AntiHBs_isJianCha\":\"\",\"chuanRanBing_HBeAg_val\":\"\",\"chuanRanBing_HBeAg_isJianCha\":\"\",\"chuanRanBing_AntiHBe_val\":\"\",\"chuanRanBing_AntiHBe_isJianCha\":\"\",\"chuanRanBing_AntiHBc_val\":\"\",\"chuanRanBing_AntiHBc_isJianCha\":\"\",\"chuanRanBing_HBVDNA_val\":\"\",\"chuanRanBing_HBVDNA_isJianCha\":\"\",\"chuanRanBing_AntiHCV_val\":\"\",\"chuanRanBing_AntiHCV_isJianCha\":\"未查\",\"chuanRanBing_HBVRNA_val\":\"\",\"chuanRanBing_HBVRNA_isJianCha\":\"\",\"chuanRanBing_aiZiBing_val\":\"\",\"chuanRanBing_aiZiBing_isJianCha\":\"未查\",\"chuanRanBing_meiDu_val\":\"\",\"chuanRanBing_meiDu_isJianCha\":\"未查\",\"jiHe_date\":\"2019-05-02\",\"jieHe_jieHeKangTi_val\":\"\",\"jieHe_jieHeKangTi_isJianCha\":\"\",\"jiHe_JunSuShiYan_val\":\"\",\"jiHe_JunSuShiYan_isJianCha\":\"\",\"sys_attach_photo\":[]}","versionNo":18};
var callBackFunction = function(){};
var path = '/api/Form/b713476c-738b-4058-865f-d85ac73f49ac?diseaseId=15';
nodePostGetRequest(HOST, PORT, method, bodydata, callBackFunction, path, cookie)

function nodePostGetRequest(HOST, PORT, method, bodydata, callBackFunction, path, cookie) {
    //把将要发送的body转换为json格式 
    var body = bodydata;
    var bodyString = JSON.stringify(body);
    //http 头部
    var headers = {
        'Content-Type': 'application/json',
        'Content-Length': bodyString.length,
        'Cookie': cookie
    };

    //用与发送的参数类型
    var options = {
        host: HOST, //ip
        port: PORT, //port
        path: path, //get方式使用的地址
        method: method, //get方式或post方式
        headers: headers,
        proxy: "http://127.0.0.1:8888"
    };
    var req = http.request(options, function (res) {
        res.setEncoding('utf-8');

        var responseString = '';

        res.on('data', function (data) {
            responseString += data;
        });

        res.on('end', function () {
            //这里接收的参数是字符串形式,需要格式化成json格式使用
            var resultObject = JSON.parse(responseString);
            console.log('-----resBody-----', resultObject);
            callBackFunction(responseString);
        });

        req.on('error', function (e) {
            // TODO: handle error.
            console.log('-----error-------', e);
        });
    });
    req.write(bodyString);
    req.end();
}